<?php
 include "counter2.php";
?>
<html> <head>
<!-- Attempt to get a half-hour refresh rate -->
<meta http-equiv="Refresh" content="1800">
<?php pagehead("Hourly statistics", "head") ?>
</head>

<body>
<?php pagetop("Linux Counter Statistics") ?> 
This is where I keep statistics about how well the
counter runs. It's always going to be half baked.
<p>
See also the <a href="stats.html">per-day statistics</a>
<p>
Statistics at <?php echo gmstrftime ("%b %d %Y %H:%M:%S",time()) ?>:<br>
<?php
if (!$days) {
   $days = 1;
   $hours = 24;
} else {
   $hours = $days * 24;
}

echo "New persons last $hours hours: ";
echo dbcount("persons", "f_ctime > date_sub(now(), interval $days day)");
echo "<br>";
echo "Updated persons last $hours hours: ";
echo dbcount("persons", "f_mtime > date_sub(now(), interval $days day) and f_mtime <> f_ctime");
echo "<br>";
echo "Logins last $hours hours: ";
echo dbcount("users", "logintime > date_sub(now(), interval $days day)");
echo "<br>";
?>

<h2>Number of visitors per hour, last 3 days</h2>
<img src="visitorshour.png">
<h2>Number of operations per hour, last 3 days</h2>
<img src="byhour.png">

<h2>Number of Web accesses per hour, last 3 days</h2>
<img src="wwwbyhour.png">

<h2>Busiest countries for update and registration</h2>
For the last <?php echo $hours?> hours

<table border>
<tr><td>
<h3>Registrations</h3>
<table>
<tr><th>Count</th><th>CC</th><th align=left>Country</th></tr>
<?php 
$query = mysql_query("select count(*) as c, country, places.longname
 from persons, places
 where persons.f_ctime > date_sub(now(), interval $days day)
       and places.name = country 
       group by country order by c desc limit 10");
  while ($arr = mysql_fetch_row($query)) {
     echo "<tr><td>$arr[0]</td>";
     echo "<td>$arr[1]</td>";
     echo "<td>$arr[2]</td></tr>";
  }


?>
</table>
</td>

<td>
<h3>Updates</h3>
<table>
<tr><th>Count</th><th>CC</th><th align=left>Country</th></tr>
<?php
$query = mysql_query("select count(*) as c, country, places.longname
 from persons, places
 where persons.f_mtime > date_sub(now(), interval $days day)
       and persons.f_mtime <> persons.f_ctime
       and places.name = country 
       group by country order by c desc limit 10");
  while ($arr = mysql_fetch_row($query)) {
     echo "<tr><td>$arr[0]</td>";
     echo "<td>$arr[1]</td>";
     echo "<td>$arr[2]</td></tr>";
  }


?>
</table>
</table>

<?php pagebottom() ?>
</body>
</html>
